//author:jxx


//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    onInit () {
      //点击单元格编辑与结束编辑(默认是点击单元格编辑，鼠标离开结束编辑)
      this.detailOptions.clickEdit = true;
      // label宽度
      this.boxOptions.labelWidth = 140
      // 弹框宽度
      this.boxOptions.width = 1000
      this.boxOptions.height = 500

      let restaurant_Type = this.getFormOption('restaurant_Type')
      let hotel_ID = this.getFormOption('hotel_ID')
      let trade_point = this.getFormOption('trade_point')
      restaurant_Type.onChange = (n, o) => {
        if (n == 0) {
          hotel_ID.hidden = true
          hotel_ID.required = false
          trade_point.required = false
          trade_point.hidden = true
        } else {
          hotel_ID.hidden = false
          hotel_ID.required = true
          trade_point.required = true
          trade_point.hidden = false
        }
      }
      let is_open = this.getFormOption('is_open')
      let distributorNews_id = this.getFormOption('distributorNews_id')
      let pram = { "page": 1, "rows": 30, "sort": "createDate", "order": "desc", "wheres": "[{\"name\":\"distributorType\",\"value\":\"2004\",\"displayType\":\"select\"}]" }
      this.http.post("/api/DistributorNews/getPageData", pram).then(res => {
        distributorNews_id.data = res.rows.map(i => {
          return {
            key: i.id,
            value: i.distributorName
          }
        })
      })

      is_open.onChange = (v) => {
        if (v == 1) {
          distributorNews_id.hidden = false
        } else {
          distributorNews_id.hidden = true
        }
      }
    },
    modelOpenAfter (row) {
      let hotel_ID = this.getFormOption('hotel_ID')
      let trade_point = this.getFormOption('trade_point')
      let distributorNews_id = this.getFormOption('distributorNews_id')
      if (this.currentAction == 'Add') {
        hotel_ID.hidden = true
        trade_point.hidden = true
        hotel_ID.required = false
        trade_point.required = false
        this.editFormFields.is_open = 0
      } else {
        if (row.restaurant_Type == 0) {
          hotel_ID.hidden = true
          hotel_ID.required = false
          trade_point.hidden = true
          trade_point.required = false
        } else {
          hotel_ID.hidden = false
          hotel_ID.required = true
          trade_point.hidden = false
          trade_point.required = true
        }
        if (row.is_open == 1) {
          distributorNews_id.hidden = false
        } else {
          distributorNews_id.hidden = true
        }
      }
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    // addBefore(formData) { //新建保存前formData为对象，包括明细表
    //   // return this.veriFromTable(formData)
    // },
    // updateBefore(formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
    //   // return this.veriFromTable(formData)
    // },
    // // 保存前编辑 
    // veriFromTable(formData) {
    //   console.log(formData)
    //   // if (formData.mainData.restaurant_Image == "") {
    //   //   this.$message.error("请选择餐厅头图")
    //   //   return false
    //   // } else {
    //   //   return true
    //   // }

    // },
    delBeforeDataAsync (ids, rows) {
      let hotel_ID = rows.map(i => i.hotel_ID)
      let hotel_status = hotel_ID.some(i => i != null)
      let obj = {
        url: '',
        params: {}
      }
      if (hotel_status) {
        obj = {
          url: '/api/Hotels/getPageData',
          params: {
            order: "desc",
            page: 1,
            rows: 30,
            sort: "createDate",
            wheres: `[{\"name\":\"hotel_ID\",\"value\":\"${hotel_ID.join()}\",\"displayType\":\"checkbox\"}]`
          }
        }
      } else {
        obj = {
          url: '/api/Hotels/getPageData',
          params: {
            order: "desc",
            page: 1,
            rows: 30,
            sort: "createDate",
            wheres: `[{\"name\":\"hotel_ID\",\"value\":\"null\",\"displayType\":\"checkbox\"}]`
          }
        }
      }
      return obj
    }
  }
};
export default extension;